var salt = sessionStorage.getItem('usersalt');

layui.use(['form', 'layer', 'laytpl'], function() {
	var form = layui.form,
		layer = parent.layer === undefined ? layui.layer : top.layer,
		$ = layui.jquery,
		laytpl = layui.laytpl;
	
	//获取学习情况详情
	function getCourseStudyDetail(){
		$.ajax({
			url: url + "course/getStudyInfo",
			dataType: "json",
			async: true,
			type: "post",
			data: {
				Token: salt,
				id : detailId
			},
			success: function(data){
				if (data.code == 0) {
					courseStudy = data.data;
					$("#name").html(courseStudy.userName);
					$("#number").html(courseStudy.userNo);
					$("#unitName").html(courseStudy.entName);
					$("#phone").html(courseStudy.phone);
		
					getSingleStudyList();
				} else {
					setTimeout(function(){
						layer.msg(data.msg);
					}, 1000);
					courseId = false;
				}
			},
			error: function(error){
				console.log("获取失败");
			}
		});
	}
	
	//获取课程学习列表
	function getSingleStudyList(){
		$.ajax({
			url: url + "course/getSingleStudyList",
			dataType: "json",
			async: true,
			type: "post",
			data: {
				Token: salt,
				userId : courseStudy.userId
			},
			success: function(data){
				if (data.code == 0) {
					//渲染表格数据
					var record = {list: null,total: courseStudy.duration};
					record.list = data.data;
					var timeBody = $("#timeBody").html();
                    laytpl(timeBody).render(record, function(html){
					  	$("#timeBodyView").html(html);
					});
				} else {
					setTimeout(function(){
						layer.msg(data.msg);
					}, 1000);
					courseId = false;
				}
			},
			error: function(error){
				console.log("获取失败");
			}
		});
	}
	
	var detailId = getQueryVariable("id");
	var courseStudy;
	if (detailId != false) {
		getCourseStudyDetail();
	}
	
	//导出
	$(".export_btn").click(function(){
		$.post(url + 'course/exportInfo', {
				Token: salt,
				ids: detailId
			}, function(result) {
				window.open(url + "file" + result.data);
			});
	});
});